﻿@using MvcApplication4.Models
@model IEnumerable<tb_Paciente>

@{
    ViewBag.Title = "Pacientes Cadastrados";
    //Layout = "~/Views/Shared/_Layout.cshtml";
    Layout = "~/Views/Shared/LayouytTeste.cshtml";
}

    <h2>Pacientes Cadastrados</h2>
    <br/>
    @Html.ActionLink("Cadastrar Paciente", "Create", "CadastroPaciente") 
    @*@Html.ActionLink("Cadastrar Dependente", "Create", "Dependente")*@
    <br/>
    <br/>

    @{
        Html.Syncfusion().Grid<tb_Paciente>("GenericListGrid")
            .Datasource(Model)
            .Caption("Pacientes Cadastrados")
            .EnablePaging()
            .EnableSorting()
            .EnableFiltering()
            .AutoFormat(Skins.Turquoise)
            .AllowResizing(true)
            .ClientSideEvents(e => e.OnToolbarClickEvent("pdf_export"))
            .ToolBar(toolbar =>
                {
                    toolbar.Add(GridToolBarItems.ExcelExport, "Excel")
                           .Add(GridToolBarItems.WordExport, "Word")
                           .Add(GridToolBarItems.PDFExport, "PDF");
                })
            .Mappers(map =>
                {
                    map.ExportExcelAction("ExportToExcel")
                       .ExportWordAction("ExportToWord")
                       .ExportPdfAction("ExportToPDF");
                })
            // .AllowAutoWrap(true)
            // .ResizeSettings(resize =>
            //{
            //    resize.ResizeToFit(true);
            //    resize.ClipContent(true);
            //})
            .Column(cols =>
                {
                    cols.Add(c => c.ID_Paciente).HeaderText("ID").TextAlign(Syncfusion.Mvc.Grid.TextAlignment.Right).Width(40);
                    cols.Add(c => c.Nome_Paciente).HeaderText("Nome Paciente").Width(100);
                    //cols.Add(c => c.Nome_Mae).HeaderText("Nome Mãe").Width(100);
                    cols.Add(c => c.CPF).HeaderText("CPF").Width(80);
                    cols.Add(c => c.Data_Nascimento).HeaderText("Data de Nascimento");
                    cols.Add(c => c.Cidade).HeaderText("Cidade").Width(80);
                    cols.Add(c => c.Endereco).HeaderText("Endereço").Width(120);
                    cols.Add(c => c.Bairro).HeaderText("Bairro").Width(70);
                    cols.Add(c => c.Estado).HeaderText("Estado").Width(65);
                    cols.Add(c => c.Telefone).HeaderText("Telefone").Width(90);
                    //cols.Add(c => c.Email).HeaderText("Email").Width(130);
                    cols.Add("Editar").HeaderText("Editar?").Format("<a href=/CadastroPaciente/Edit/{ID_Paciente}>Editar</a>").Width(50);
                    cols.Add("Deletar").HeaderText("Deletar?").Format("<a href=/CadastroPaciente/Delete/{ID_Paciente}>Deletar</a>").Width(80);

                })
            //.ChildGrid(child =>
            //{
            //    child.ChildGridTemplate(Html.Syncfusion().Grid<tb_Dependente>("ChildGrid_${ID_Paciente}")
            //    .Caption("Child Teste")
            //    .Column(c =>
            //    {
            //        //c.Add(p => p.ID_Dependente).HeaderText("ID Dependente").TextAlign(TextAlignment.Right);
            //        //c.Add(p => p.ID_Paciente).HeaderText("ID Paciente").TextAlign(TextAlignment.Right);
            //        c.Add(p => p.Nome_Dependente).HeaderText("Nome Dependente").TextAlign(TextAlignment.Left);
            //        c.Add(p => p.Dt_Nascimento).HeaderText("Data de Nascimento").TextAlign(TextAlignment.Left);
            //        c.Add("Editar").HeaderText("Editar?").Format("<a href=/Dependente/Edit/{ID_Dependente}>Editar</a>");
            //        c.Add("Deletar").HeaderText("Deletar?").Format("<a href=/Dependente/Delete/{ID_Dependente}>Deletar</a>");
            //    })
            //    .AllowResizing(true)
            //    .AutoFormat(Skins.Turquoise)
            //    .ToolBar(toolbar =>
            //    {
            //        toolbar.Add(GridToolBarItems.ExcelExport, "Excel")
            //               .Add(GridToolBarItems.WordExport, "Word")
            //               .Add(GridToolBarItems.PDFExport, "PDF");
            //    })
            //    .Mappers(map =>
            //        {
            //        map.ExportExcelAction("ExportToExcelChild")
            //               .ExportWordAction("ExportToWordChild")
            //               .ExportPdfAction("ExportToPDFChild");
            //        map.Action("ChildGrid", new { ID_Paciente = "${ID_Paciente}" });
            //    })
            //    .ToChildGridTemplate());
            //})
            .Render();
    }
    
    
<script type="text/javascript">

         function pdf_export(sender, args) {



             if (args._currentItemId == sender._ID + 'pdf_export'

            || args._currentItemId == sender._ID + 'word_export'

            || args._currentItemId == sender._ID + 'excel_export') {

                 var _VisibleColumns = new Array();

                 $.each(sender.get_VisibleColumns(), function (index, Column) {

                     if (Column.Name == "Editar") {

                         Column.Visible = false; //removing columns for export

                     }

                     if (Column.Name == "Deletar") {

                         Column.Visible = false; //removing columns for export

                     }

                     if (Column.Visible == true) {

                         _VisibleColumns.push(Column); //visible columns

                     }

                 });

                 sender.set_VisibleColumns(Sys.Serialization.JavaScriptSerializer.serialize(_VisibleColumns)); //Set visible columns.

             }

         }

 

</script>